#ifndef RPCPROVIDER_HPP
#define RPCPROVIDER_HPP

#include </usr/local/include/muduo/net/EventLoop.h>
#include </usr/local/include/muduo/net/InetAddress.h>
#include </usr/local/include/muduo/net/TcpConnection.h>
#include </usr/local/include/muduo/net/TcpServer.h>
#include "../example/rpc.pb.h"
#include <iostream>
#include <unordered_map>

//RpcProvider的构造函数比较重要，因为他是Rpc业务的提供者，需要接受各种类型
class RpcProvider
{
public:
    bool NotifyService(::google::protobuf::Service* serivce);

    //启动Rpc服务
    void start();


    
private:
    void OnConnection(const muduo::net::TcpConnectionPtr&);
    
    
    void OnMessage(const muduo::net::TcpConnectionPtr&,
                            muduo::net::Buffer*,
                            muduo::Timestamp);

    bool PrintRegisterService();
    
    void ResponseSend(const muduo::net::TcpConnectionPtr&,::google::protobuf::Message* responce);

    muduo::net::EventLoop _eventloop;

    //以下两个表专门记录用户注册的对应的服务类信息，和对应的调用方法
    struct ServiceInfo
    {
        ::google::protobuf::Service* pService;
        //key : MethodName , value : MethodName;
        std::unordered_map<std::string,const::google::protobuf::MethodDescriptor*> _serviceMethodMap;
    };
    //key : serviceName , value : ServiceInfo;
    std::unordered_map<std::string, ServiceInfo> _serviceInfoMap;

};


#endif